package com.xiguaji.boot.eventbus;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.DefaultManagedAwareThreadFactory;

import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class EventBusConfiguration {

    @Bean
    public EventBusTemplate eventBusTemplate(List<IEventListener> eventListeners) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 0, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(), new DefaultManagedAwareThreadFactory());
        return new EventBusTemplate(eventListeners, executor);
    }
}
